package com.rj.core.collections;

import java.util.HashMap;

/**
 * 数据处理Map
 *
 * @author YFX_RANLUBO
 * @date 2022/10/20 17:11
 **/
public class DataHandlerMap<K, V> extends HashMap<K, V> {
    protected static final ThreadLocal<DataHandlerMapMonitor> LOCAL = new ThreadLocal();
    /**
     * 设置监听器
     *
     * @param monitor
     */
    public static void addMonitor(DataHandlerMapMonitor monitor) {
        LOCAL.set(monitor);
    }
    @Override
    public V put(K key, V value) {
        DataHandlerMapMonitor monitor = LOCAL.get();
        if (monitor != null) {
            monitor.handler(key, value);
        }
        return super.put(key, value);
    }
}
